////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                           BailterRay                                       //
//                    Pip Robbins & Zhao Zhang                                //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
class BailterRayUIScene_MidGameMenu extends UTUIScene_MidGameMenu;


event BeginLoading()
{
    local UTPlayerController PC;
    local UISceneClient SC;

    SC = GetSceneClient();
    PC = GetUTPlayerOwner();

    bReturningToMainMenu = true;
    SC.CloseScene(self);
    PC.QuitToMainMenu();
}

function RemoveGameVoteTab()
{
	local WorldInfo WI;
	local UTGameReplicationInfo GRI;

	//Remove the "game" tab if we are in Instant Action
	WI = GetWorldInfo();
	if (WI != none && WI.NetMode == NM_Standalone && InGamePage.GetOwnerTabControl() != None)
	{
		GRI = UTGameReplicationInfo(WI.GRI);
		if (GRI != None && !GRI.bStoryMode)
		{
			TabControl.RemovePage(InGamePage, 0);
		}
		else
		{
			`log("Didn't remove"@InGamePage.GetOwnerTabControl()@"GRI:"@(GRI != None)@"Story:"@GRI.bStoryMode);
		}
	}
}

event PostInitialize( )
{
	local class<UTGame> GameClass;
	local UTPlayerController PC;



	// Store a reference to the button bar.
	ButtonBar = UTUIButtonBar(FindChild('ButtonBar', true));
	ButtonBar.ClearButton(0);
	ButtonBar.ClearButton(1);

	LoadingPanel = UIPanel(FindChild('LoadingPanel',true));
	LoadingRotator = UIImage(FindChild('ConnectingImage',true));
	LoadingLabel = UILabel(FindChild('LoadingLabel', true));

	MapVoteClock = UILabel(FindChild('MapVoteClock',true));

	// Find the tab control

	TabControl = UTUITabControl( FindChild('TabControl',true) );

	if ( TabControl != none )
	{

		GameClass = Class<UTGame>( GetWorldInfo().GRI.GameClass);
		if ( GameClass != none && !GameClass.default.bMidGameHasMap )
		{
			TabControl.RemoveTabByTag('MapTab');
		}

		TabControl.OnPageActivated = OnPageActivated;

		if ( GetWorldInfo().NetMode == NM_StandALone || IsConsole() )
		{
			TabControl.RemoveTabByTag('ChatTab');
		}

		if ( GetWorldInfo().NetMode == NM_StandALone)
		{
			TabControl.RemoveTabByTag('FriendsTab');
			TabControl.RemoveTabByTag('MessageTab');
		}
	}

	// Setup initial button bar
	SetupButtonBar();

	// Setup handler for input keys
	OnRawInputKey=HandleInputKey;
	OnPreRenderCallBack = PreRenderCallBack;

	InGamePage = UTUITabPage_InGame(FindChild('GameTab',true));

	VotePage = UTUITabPage_VoteTab(FindChild('VoteTab', True));

	// Disable the Vote tab until it is needed (note: the vote tab gets reordered when shown)
	PC = GetUTPlayerOwner(0);

	if (PC == none || PC.VoteRI == none)
		TabControl.RemoveTabByTag('VoteTab');
	else
		RepositionVotePage();

	TabControl.RemoveTabByTag('GameTab');

}
function SetupButtonBar()
{
	local UTGameReplicationInfo GRI;
	local WorldInfo WI;
	local UTPlayerController UTPC;

	if(ButtonBar != none)
	{
	    	WI = GetWorldInfo();
    		GRI = UTGameReplicationInfo(WI.GRI);

		ButtonBar.Clear();

		// Depending on when we are, set the proper button.

		if ( WI != none )
		{
			if ( !WI.IsInSeamlessTravel() )
			{
				if ( bWaitingForReady )
				{
				    //ButtonBar.AppendButton("<Strings:UTGameUI.ButtonCallouts.Ready>", ButtonBarBack);
				}
				else
				{
				    //ButtonBar.AppendButton("<Strings:UTGameUI.ButtonCallouts.Back>", ButtonBarBack);
				}

				if (WI.NetMode == NM_StandAlone || (GRI != None && GRI.bStoryMode))
				{
					ButtonBar.AppendButton("<Strings:UTGameUI.MidGameMenu.Forfeit>",ButtonBarDisconnect);
				}
				else
				{
					//ButtonBar.AppendButton("<Strings:UTGameUI.MidGameMenu.LeaveGame>",ButtonBarDisconnect);
				}

				ButtonBar.AppendButton("<Strings:UTGameUI.ButtonCallouts.ExitGame>",ButtonBarExitGame);

				if (TabControl != None && (!bWaitingForReady || UTUITabPage_InGame(TabControl.ActivePage) != None))
				{
					// Let the current tab page try to setup the button bar
					//UTTabPage(TabControl.ActivePage).SetupButtonBar(ButtonBar);


				}

				UTPC = GetUTPlayerOwner();
				if ( (UTPC != None) && (UTPC.PlayerReplicationInfo != None) && UTPC.PlayerReplicationInfo.bOnlySpectator )
				{
				    //ButtonBar.AppendButton("<Strings:UTGameUI.ButtonCallouts.JoinServer>", ButtonBarJoin);
				}
			}
			else
			{
				if (WI.NetMode == NM_StandAlone || (GRI != None && GRI.bStoryMode))
				{
					ButtonBar.AppendButton("<Strings:UTGameUI.MidGameMenu.Forfeit>", ButtonBarDisconnect);
				}
				else
				{
					//ButtonBar.AppendButton("<Strings:UTGameUI.MidGameMenu.LeaveGame>", ButtonBarDisconnect);
				}
				ButtonBar.AppendButton("<Strings:UTGameUI.ButtonCallouts.ExitGame>", ButtonBarExitGame);
			}
		}
	}
}

function bool ButtonBarExitGame(UIScreenObject InButton, int InPlayerIndex)
{
    ConsoleCommand("Quit");
    return true;
}

event TickLoading(float DeltaTime)
{

}

event EndLoading()
{

}

defaultproperties
{

}